<div class="icon icon5">
    <div class="wp clearfix">
        <div class="tit1">一件出色的作品也许就从这封邮件开始</div>
        <div class="imsg">
            <ul>
                <form id="msg_form" action="{:U('Message/add')}" method="post" >
                    <li><div class="pd"><input class="ipt_t1" type="text" name="email" placeholder="您的电子邮箱"></div></li>
                    <li><div class="pd"><input class="ipt_t1" type="text" name="name" placeholder="您的姓名"></div></li>
                    <li><div class="pd"><input class="ipt_t1" type="text" name="mobile" placeholder="联系手机"></div></li>
                    <li><div class="pd"><input class="ipt_t1" type="text" name="company" placeholder="公司名称"></div></li>
                    <li class="w100"><div class="pd"><textarea class="textarea1" name="message" id="message" placeholder="您的需求"></textarea></div></li>
                </form>
                <li class="w100"><div class="pd"><input class="ipt_b1 sent_btn" type="submit" value="发送" onclick="checkForm(this)"></div></li>
            </ul>
        </div>
    </div>
</div>
<script type="text/javascript">
    function checkForm(){
        var targetUrl = $("#msg_form").attr("action");
        var email   = $.trim($('input[name=email]').val());
        var name    = $.trim($('input[name=name]').val());
        var mobile  = $.trim($('input[name=mobile]').val());
        var company = $.trim($('input[name=company]').val());
        var message = $.trim($('#message').val());
        //验证
        var mail=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        var phone=/^1[34578]\d{9}$/;

        if(email.match(mail)==null){
            alert("您的邮箱格式不正确");
            return false;
        }

        if(name.length == 0){
            alert("请填写您的姓名");
            return false;
        }

        if(mobile.match(phone)==null){
            alert("您的联系手机格式不正确");
            return false;
        }

        if(company.length == 0){
            alert("请填写您的公司名称");
            return false;
        }

        if(message.length == 0){
            alert("请填写您的需求内容");
            return false;
        }
        var data = $("#msg_form").serialize();

        $.ajax({
            type:'post',
            url:targetUrl,
            cache: false,
            data:data,
            dataType:'json',
            success:function(data){
                alert(data.message);
                $('#msg_form')[0].reset();
            },
            error:function(){
                alert("发送失败")
            }
        })
    }
</script>